﻿<%@ Page Title="" Language="C#" MasterPageFile="~/ShopCart/ShopCartMaster.Master" AutoEventWireup="true" CodeBehind="ShoppingCartConfirm.aspx.cs" Inherits="ZLCMS.Web.ShopCart.ShoppingCartConfirm" %>

<%@ MasterType VirtualPath="~/ShopCart/ShopCartMaster.Master" %>
<%@ Import Namespace ="ZLCMS.Business.Util" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<form id="form_submit_order" runat="Server" class="registerform">
<!--wrapper start-->
<div id="main">
	<div class="regist_top">
      <!--logo start-->
      <div class="regist_logo"><a href="#"><img src="/MemberUser/images/logo.png" width="147" height="69" /></a></div>
      <!--logo end-->
      <div class="regist_yous"><img src="/MemberUser/images/order_submit.jpg" width="486" height="48" /></div>
      <div class="clear"></div>
    </div>
    
    <div class="order_submit">
   	   <h5>核对订单信息</h5>
        <div class="submit_box">
        	<div class="item">
           	  <div class="title"><div style="float: left;">收货人信息：</div><div id="addrtip" class="checktip"></div></div>
              <div class="clear"></div>
              <div id="div_address">
                <asp:repeater runat="server" id="rp_addr">
                    <ItemTemplate>
                        <p>
                        <input onclick='choiceOption(this,"address")' <%# Eval("Status").ToString()=="1"?"checked='checked'":"" %> id="addr<%# Eval("Id") %>" class="pr1" type="radio" name="addr" value="<%# Eval("Id") %>" <%# Container.ItemIndex == 0 ? "datatype='*'" : "" %> msgtiprel="addrtip"/>
                        <label for="addr<%# Eval("Id") %>"><%# Eval("Receiver")%>,<%# ParamKit.GetValue("Province", Eval("Province"), "")%>,<%# ParamKit.GetValue("City", Eval("City"), "")%>,<%# ParamKit.GetValue("Area", Eval("Area"), "")%>,<%# Eval("Address")%>,<%# Eval("Phone")%></label>
                        </p>
                    </ItemTemplate>
                </asp:repeater></div><!-- rp_product -->
                <input id="addrnew" class="pr1" type="radio" msgtiprel="addrtip" value="-1" name="addr" />
                <label for="addrnew">使用新地址</label>

    <div style="margin-left: 20px; display:none" id="newaddress">
       <div command="SaveAddress" id="form_create_address">
        <div class="os_line"><label>姓&nbsp;&nbsp;&nbsp;&nbsp;名：</label>
            <asp:TextBox ID="TextBoxName" runat="server"  datatype="s2-12"  errormsg="请填写正确的收货人姓名！" nullmsg="请填写收货人姓名！" msgtiprel="addrtip" command-param='Receiver'></asp:TextBox>
        </div>
        <div style="height: 30px;">
        <label>所在城市：</label>
          <select  name="province" datatype="*"  command-param='Province'  runat="server" Width="120px"   id="sel_province">
            </select> - 
             <select   command-param='City'  datatype="*"   runat="server"   name="city"  id="sel_city" Width="120px" >
                <option value="-1">请选择</option>
            </select>  - 
                <select   command-param='Area'   datatype="*"    runat="server" Width="120px"  
                name="area" id="sel_area" class="area"  errormsg="请选择所在城市！" nullmsg="请选择所在城市！" msgtiprel="addrtip">
                <option value="-1">请选择</option>
            </select>
        </div>
        <div style="height: 30px;">
        <label>地&nbsp;&nbsp;&nbsp;&nbsp;址：</label>
            <asp:TextBox ID="TextBoxAddress" command-param='Address' runat="server"  datatype="s6-30"  errormsg="请填写正确的收货地址！" nullmsg="请填写收货地址！" msgtiprel="addrtip"></asp:TextBox>
            <div><span class="Validform_checktip"></span></div>
        </div>
        <div style="height: 30px;">
        <label>联系电话：</label>
            <asp:TextBox ID="TextBoxMobile" command-param='Phone'  runat="server" datatype="m" errormsg="请输入正确的收货人电话！" nullmsg="请输入收货人电话！" msgtiprel="addrtip"></asp:TextBox>
<div><span class="Validform_checktip"></span></div>
        </div>
         <div style="height: 30px;">
                   设为默认地址 <input id="ckb_default_address" value="" type="checkbox" 
                    onclick="setDefaultAddress(this)" />
         </div>
         <div style="height: 30px;">
          <input type="hidden" id="hid_default_address" value="0" command-param='Status' />
         </div>
         </div>
    </div>
            </div>
            <% if (existNormalPro == true)
               { %>
        	<div class="item">
           	  <div class="title"><div style="float: left;">送货方式：</div><div id="gendertip" class="checktip"></div></div>
                <div>
                <asp:repeater runat="server" id="rp_shipping">
                    <ItemTemplate>
                        <p>
                        <input onclick="choiceOption(this,'shipping')" id="ship<%# Eval("Id") %>" class="pr1" shippingprice='<%# Eval("Expression") %>' type="radio" name="shipping" value="<%# Eval("Id") %>" <%# Container.ItemIndex == 0 ? "datatype='*'" : "" %> msgtiprel="gendertip"/>
                        <label for="ship<%# Eval("Id") %>"><%# Eval("ShippingName") %> <%# Eval("Description") %></label>
                        </p>
                    </ItemTemplate>
                </asp:repeater><!-- rp_product -->
                </div>
            </div>
            <%} %>
        	<div class="item">
           	  <div class="title"><div style="float: left;">支付方式：</div><div id="paytip" class="checktip"></div></div>
                <asp:repeater runat="server" id="rp_pay">
                    <ItemTemplate>
                        <p>
                        <input  onclick="choiceOption(this,'payment')"  id="pay<%# Eval("Id") %>" class="pr1" type="radio" name="pay" value="<%# Eval("Id") %>" <%# Container.ItemIndex == 0 ? "datatype='*'" : "" %> msgtiprel="paytip"/>
                        <label for="pay<%# Eval("Id") %>"><%# Eval("PaymentName") %></label>
                        </p>
                    </ItemTemplate>
                </asp:repeater><!-- rp_product -->
            </div>
        	<div class="item">
           	  <div class="title">备注</div>
              <p>
                <textarea name="" cols="" rows=""  id="txt_remark"  name="order_form_elem"   command-param='Remark'  ></textarea>
              </p>
            </div>
        </div>
    </div>
    <div class="cart_cbox">
    	<ul class="title">
            <li class="pro">产品</li>
            <li>数量</li>
            <li>单价</li>
            <li>小计</li>
            <div class="clear"></div>
        </ul>
        <asp:Repeater ID="rptPro" runat="server">
        <ItemTemplate>
          <ul class="pro_detail">
            <li class="pro"><a href='/product/ProductDetail.aspx?no=<%# Eval("ProductNo") %>'><img src='<%# FileKit.FirstImgPathThumb(Eval("ImageUrl") as string) %>' width="59" height="59" /></a>
            	<div class="pro_text">  <%# Eval("ProductName") %><%# GetSkuItemHtml(Eval("ParamCode") == null ? "" :Convert.ToString(  Eval("ParamCode")))%></div>
            </li>
            <li class="numn"><%# Eval("ProductCount")%><div class="clear"></div></li>
            <li>￥<%#Convert.ToDecimal(Eval("UnitPrice"))%></li>
            <li>￥<%# string.Format("{0:0.##}", Convert.ToInt32(Eval("ProductCount")) * Convert.ToDecimal(Eval("UnitPrice")))%></li>
            <div class="clear"></div>
        </ul>
        </ItemTemplate>
        </asp:Repeater>
      
    </div>
    
    <div class="jiesuanlan">
    	<div class="p_left">
        	<a href="/ShopCart/ShoppingCart.aspx" class="button">返回购物车</a>
        </div>
        <div class="p_right">
        	共<span><%=_totalCount %></span>件商品&nbsp;&nbsp;应付总额<label></label>：<strong>￥</strong><strong id="strong_totalprice" totalprice='<%=_totalPrice %>'><%=_totalPrice %></strong>（运费：￥<font id="shippingPrice">0</font>）&nbsp;&nbsp;

            <input type="hidden" id="hid_address" name="order_form_elem"   command-param='AddressId'  />
         <input type="hidden" id="hid_payment"  name="order_form_elem"   command-param='PaymentId'  />

        <input type="hidden" id="hid_shipping"  name="order_form_elem"   command-param='ShippingId'  value='<%=existNormalPro==true?"":"3" %>'/>

         <input type="hidden" id="hid_kind"  name="order_form_elem"   command-param='Kind' value='<%=Request["kind"] %>'  />
         <input type="hidden" id="hid_products"   name="order_form_elem"  command-param='ProductsJsonStr'  value='<%= Request["products"] %>' />
              <a  href="javascript:void(0);"  id="input_submit"  onclick="submitOrder($('#main'))"  >提交订单</a>
         
        </div>
        <div class="clear"></div>
    </div>
    
</div>
<!--wrapper end-->

</form>

<script type="text/javascript">
    $(function () {

        $("input[name=addr]").click(function () {
            $this = $(this);
            if ($this.val() == "-1") {
                $("#newaddress").css("display", "block");
            }
            else {
                $("#newaddress").css("display", "none");
            }
        });

        $("input[name=shipping]").each(function () {
            $(this).click(function () {
                $("#shippingPrice").html($(this).attr("shippingprice"));
                $("#strong_totalprice").html(parseFloat($("#strong_totalprice").attr("totalprice")) + parseFloat($(this).attr("shippingprice")));
            });
        });

        //Bind Cities when Provinces selected change
        $("select#<%=sel_province.ClientID %>").change(function () {
            var provinceCode = $("select#<%=sel_province.ClientID %>").val();
            $("select#<%=sel_province.ClientID %>").ExecuteCommand({
                successCallBack: function (result) {
                    //判断是否处于页面初始化状态
                    var binitialize = false;

                    if (result) {
                        var _html = '<option value="-1" >请选择</option>';
                        for (var i = 0; i < result.length; i++) {
                            _html += '<option value=' + result[i].Key + '>' + result[i].Value + '</option>';

                        }
                        $("select#<%=sel_city.ClientID %>").empty().append(_html);
                        if (binitialize) {
                            $("select#<%=sel_city.ClientID %>").trigger('change');
                        }
                    }
                },
                errorCallback: function (errorCode, msg) {
                    alert(msg);
                }
            }, 'LoadAddress', { Category: 'City', KeyValuePairString: 'Province:' + provinceCode });
        });


        //Bind Areas when Cites selected change
        $("select#<%=sel_city.ClientID %>").change(function () {
            var CityCode = $("select#<%=sel_city.ClientID %>").val();
            $("select#<%=sel_city.ClientID %>").ExecuteCommand({
                successCallBack: function (result) {
                    if (result) {
                        var _html = '<option value="-1" >请选择</option>';
                        for (var i = 0; i < result.length; i++) {

                            _html += '<option value=' + result[i].Key + '>' + result[i].Value + '</option>';

                        }
                        $("select#<%=sel_area.ClientID %>").empty().append(_html);
                    }
                },
                errorCallback: function (errorCode, msg) {
                    alert(msg);
                }
            }, 'LoadAddress', { Category: 'Area', KeyValuePairString: 'City:' + CityCode });
        });


        $("select#<%=sel_province.ClientID %>").change();
        // $(".registerform").openValidform();
        gValidForm = $(".registerform").openValidformTip(function (msg, o, cssctl) {
            var objtip = $("#" + o.obj.attr("msgtiprel"));
            if (o.obj.attr("name") == "addr") {
                if ($("input[name='addr']:checked").val() == "-1") {
                    $("#addrtip").html("");
                    $("#addrtip").removeClass("Validform_right Validform_wrong")
                    return;
                }
            }
            cssctl(objtip, o.type);
            objtip.text(msg);
        });

        $("#hid_address").val($("input[name=addr][checked]").val());
    });

    var gValidForm;


function setDefaultAddress(ct) {

    var $this = $(ct);
    if ($this.is(":checked")) {
        $("#hid_default_address").val("1");
    } 
    else {
        $("#hid_default_address").val("0");
    }
}

function choiceOption(ct, param) {
    if(param=='address'){
        $("#hid_address").val($(ct).val());
    }
    else if (param == 'payment') {
        $("#hid_payment").val($(ct).val());
    }
    else if (param == 'shipping') {
        $("#hid_shipping").val($(ct).val());
    }
}

function submitOrder(ct) {
    if (gValidForm.check()) {
        if (confirm("确认提交订单吗？提交后将生成既定订单，不能修改！！")) {
        var addressId=$("#hid_address").val();
        if ($("#newaddress").css("display") == "block") {
            $('#<%=form_submit_order.ClientID %>').ExecuteCommand({
                successCallBack: function (result) {
                    if (result) {
                        addressId = result.Id;
                        $(ct).ExecuteCommand({
                            successCallBack: function (result) {
                                if (result) {
                                    alert(result.OrderNo);
                                }
                            },
                            errorCallback: function (errorCode, msg) {
                                alert(msg);
                            }
                        }, 'SubmitOrder', {
                            PaymentId: $('#hid_payment').val(),
                            ShippingId: $('#hid_shipping').val(),
                            ProductsJsonStr: $('#hid_products').val(),
                            Kind: $('#hid_kind').val(),
                            AddressId: addressId,
                            Remark: $('#txt_remark').val()
                        });
                    }
                },
                errorCallback: function (errorCode, msg) {
                    alert(msg);
                }
            }, 'SaveAddress', {
                Receiver: $('#<%=TextBoxName.ClientID %>').val(),
                Phone: $('#<%=TextBoxMobile.ClientID %>').val(),
                Province: $('#<%=sel_province.ClientID %>').val(),
                City: $('#<%=sel_city.ClientID %>').val(),
                Area: $('#<%=sel_area.ClientID %>').val(),
                Address: $('#<%=TextBoxAddress.ClientID %>').val(),
                Status: $('#hid_default_address').val()
            });
        }
        else {
            $(ct).ExecuteCommand({
                successCallBack: function (result) {
                    if (result) {
                        if (parseInt($("#hid_payment").val()) == 2 || parseInt($("#hid_payment").val()) == 4) {//当选货到付款时不跳转支付页面
                            location.href = '/memberUser/vieworder.aspx?orderno=' + result.OrderNo;
                        }
                        else {
                            location.href = "/ShopCart/ShoppingCartComfirmSuccess.aspx?orderno=" + result.OrderNo;
                        }
                    }
                },
                errorCallback: function (errorCode, msg) {
                    alert(msg);
                }
            }, 'SubmitOrder', {
                PaymentId: $('#hid_payment').val(),
                ShippingId: $('#hid_shipping').val(),
                ProductsJsonStr: $('#hid_products').val(),
                Kind: $('#hid_kind').val(),
                AddressId: addressId,
                Remark: $('#txt_remark').val()
            });
        }


        
        }
    }
   
}
</script>
</asp:Content>
